package com.crm.service.impl.cluePoolManager;

import com.crm.dao.mapper.cluePoolManager.CluePoolManagerMapper;
import com.crm.model.entity.cluePoolManager.Clue;
import com.crm.model.entity.cluePoolManager.CluePoolManager;
import com.crm.model.entity.cluePoolManager.CluePoolManagerExample;
import com.crm.service.cluePoolManager.CluePoolManagerDbService;
import com.crm.service.cluePoolManager.CluePoolPublicDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author luojie
 * @date 2021/1/11 16:38
 */
@Service
public class CluePoolManagerDbServiceImpl implements CluePoolManagerDbService {

    @Autowired
    CluePoolManagerMapper cluePoolManagerMapper;

    @Override
    public Boolean insertCluePoolManager(CluePoolManager cluePoolManager) {
        Boolean result = false;
        int num = cluePoolManagerMapper.insertSelective(cluePoolManager);
        if(num>0){
            result = true;
        }
        return result;
    }

    @Override
    public CluePoolManager selectCluePoolManagerByPoolIdAndPeopleId(String poolId, String peopleId) {
        CluePoolManagerExample cluePoolManagerExample = new CluePoolManagerExample();
        CluePoolManagerExample.Criteria criteria = cluePoolManagerExample.createCriteria();
        criteria.andCluePoolIdEqualTo(poolId);
        criteria.andManagerPeopleIdEqualTo(peopleId);
        List<CluePoolManager> cluePoolManagers =  cluePoolManagerMapper.selectByExample(cluePoolManagerExample);
        if(cluePoolManagers.size()>0){
            return cluePoolManagers.get(0);
        }else {
            return null;
        }
    }

    @Override
    public List<CluePoolManager> selectCluePoolManagerByPoolId(String poolId) {
        CluePoolManagerExample cluePoolManagerExample = new CluePoolManagerExample();
        CluePoolManagerExample.Criteria criteria = cluePoolManagerExample.createCriteria();
        criteria.andCluePoolIdEqualTo(poolId);
        List<CluePoolManager> cluePoolManagers = cluePoolManagerMapper.selectByExample(cluePoolManagerExample);
        return cluePoolManagers;
    }

    @Override
    public Boolean deleteCluePoolManager(String poolId) {
        CluePoolManagerExample cluePoolManagerExample = new CluePoolManagerExample();
        CluePoolManagerExample.Criteria criteria = cluePoolManagerExample.createCriteria();
        criteria.andCluePoolIdEqualTo(poolId);
        int num = cluePoolManagerMapper.deleteByExample(cluePoolManagerExample);
        if(num>0){
            return true;
        }else {
            return false;
        }
    }
}
